function doSearch() {
	$('#tt').datagrid('load', {
		mark : $('#mark').val(),
		isDelete : $('#isDelete').combobox('getValue'),
		sysVer:$('#sysVer').combobox('getValue')
	});
	$('#tt').datagrid('unselectAll');
}

$(function() {
	$('#dlg').dialog('close');
	$('#dlg1').dialog('close');
	$('#isDelete').combobox("select",-1);
});

function add() {
	showMyWindow('APK配置 |新增', '/apkconfig/addConfig', 800, 600);
}

function edit() {
	var row = $('#tt').datagrid('getSelected');
	var mark = row.mark;
	if (row) {
		showMyWindow('APK配置 | 编辑', '/apkconfig/' + mark + '/configUpdate', 800, 600);
	} else {
		showMsg(market.content.title, market.content.tips, alert);
	}
}

function copy() {
	var row = $('#tt').datagrid('getSelections');
	if (row.length == 0) {
		showMsg(market.content.title, "请选择一条记录！", alert);
		return false;
	}
	if (row.length > 1) {
		showMsg(market.content.title, "复制操作只能选择一条记录！", alert);
		return false;
	}
	var mark = row[0].mark;
	showMyWindow('APK配置 | 编辑', '/apkconfig/' + mark + '/configCopy', 800, 600);
}

function del() {
	var row = $('#tt').datagrid('getSelected');
	var mark = row.mark;
	$.messager.confirm('温馨提醒', '你确定删除本条数据吗？', function(r) {
		if (r) {
			$.get('/apkconfig/del?mark=' + mark, function(data) {
				if (data.return_code == '1') {
					top.showMsg(market.content.title, data.return_msg, alert);
					doSearch();
				} else if (data.return_code == '3') {
					top.showMsg(market.content.title, data.return_msg, alert);
				} else {
					$.messager.alert(market.content.title, data.return_msg);
				}
			});
		}
	});
}

function abandon() {
	var row = $('#tt').datagrid('getSelected');
	var mark = row.mark;
	var isUseful = row.isDelete;
	if(isUseful==1){
		top.showMsg(market.content.title, "数据已经是废弃状态", alert);
		return;
	}else{
		$.messager.confirm('温馨提醒', '你确定废弃本条数据吗？', function(r) {
			if (r) {
				$.get('/apkconfig/abandon?mark=' + mark, function(data) {
					if (data.return_code == '1') {
						top.showMsg(market.content.title, data.return_msg, alert);
						doSearch();
					} else if (data.return_code == '3') {
						top.showMsg(market.content.title, data.return_msg, alert);
					} else {
						$.messager.alert(market.content.title, data.return_msg);
					}
				});
			}
		});
	}
}

function effect() {
	var row = $('#tt').datagrid('getSelected');
	var mark = row.mark;
	var isUseful = row.isDelete;
	if(isUseful==0){
		top.showMsg(market.content.title, "数据已经是启用状态", alert);
		return;
	}else{
		$.messager.confirm('温馨提醒', '你确定启用本条数据吗？', function(r) {
			if (r) {
				$.get('/apkconfig/effect?mark=' + mark, function(data) {
					if (data.return_code == '1') {
						top.showMsg(market.content.title, data.return_msg, alert);
						doSearch();
					} else if (data.return_code == '3') {
						top.showMsg(market.content.title, data.return_msg, alert);
					} else {
						$.messager.alert(market.content.title, data.return_msg);
					}
				});
			}
		});
	}
}

function formatterRetent(value, row, index) {
	var a = '<a href="#" onclick="editRetent(' + "'" + row.id + "'" + ')">配置</a> ';
	return a;
}

function formatterDevice(value, row, index) {
	var a = '<a href="#" onclick="editDevice(' + "'" + row.id + "'" + ')">配置</a> ';
	return a;
}

function editRetent(id) {
	showMyWindow('APK配置| 留存执行限制', '/apkconfig/' + id + '/retentFilterConfig', 800, 400);
}

function editDevice(id) {
	showMyWindow('APK配置| 留存执行限制', '/apkconfig/' + id + '/deviceConfig', 800, 400);
}

function formatterLogin(value, row, index) {
	var a = '<a href="#" onclick="editLogin(' + "'" + row.mark + "'" + ')">配置</a> ';
	return a;
}

function formatterProvince(value, row, index) {
	var a = '<a href="#" onclick="editProvince(' + "'" + row.mark + "'" + ')">配置</a> ';
	return a;
}

function editLogin(mark) {
	showMyWindow('APK配置| 登录方式配置', '/apkconfig/' + mark + '/loginList', 800, 400);
}


function editProvince(mark) {
	showMyWindow('APK配置| 编辑省份配置', '/apkconfig/' + mark + '/provinceList', 850, 500);
}

function formatterType(value) {
	if (value == 0) {
		return "启用";
	}
	if (value == 1) {
		return "作废";
	}

}

function submitDataForm(url,obj) {
	var isDelete = $('#isDelete').combobox('getValue');
	var mark = $('#mark').val();
	var sysVer = $('#sysVer').val();
	
	$('#ff').form(
	'submit',
	{
		url : url,
		onSubmit : function() {
			$("#emark").val(mark);
			$("#eisDelete").val(isDelete);
			$("#esysVer").val(sysVer);
			
		},
		success : function(data) {
			showProcess(false);
			var data = eval('(' + data + ')');
			if (data.return_code == '1') {
				top.showMsg(market.content.title, data.return_msg, alert);
			} else {
				$.messager.alert(market.content.title, data.return_msg);
			}
		},
		onLoadError : function() {
			showProcess(false);
			$.messager.alert(market.content.title, market.content.networkError);
		}
	});
	
/*	if(obj.id){
		exportDisableAndEnable("#" + obj.id, delayTime || 10000);	
	}
*/}

function batchEditVer() {
	var rows = $('#tt').datagrid('getChecked');
	if (rows === undefined || rows.length == 0) {
		showMsg("温馨提示", "请选择要修改的记录！", alert);
		return false;
	}
	$('#dlg').dialog('open');
}

function batchEditVerSubmit() {
	var rows = $('#tt').datagrid('getChecked');
	var sysVer = $('#sysVer1').combobox('getValues');
	var marks = [];
	for (var i = 0; i < rows.length; i++) {
		marks.push(rows[i].mark);
	}
	$.ajax({
		url : '/apkconfig/batchEditVerSubmit',
		data : {
			marks : marks.join(","),
			sysVer : sysVer.join(",")
		},
		type : "POST",
		datatype : "json",
		async : true,
		success : function(data) {
			$('#dlg').dialog('close');
			$('#tt').datagrid('clearChecked');
			$('#tt').datagrid('reload');
		},
		error : function(data) {
			showMsg("温馨提示", data, alert);
		}
	});
}

function batchEditFile() {
	var rows = $('#tt').datagrid('getChecked');
	if (rows === undefined || rows.length == 0) {
		showMsg("温馨提示", "请选择要修改的记录！", alert);
		return false;
	}
	var marks = [];
	for (var i = 0; i < rows.length; i++) {
		marks.push(rows[i].mark);
	}
	
	if (rows) {
		showMyWindow('APK配置 | 批量修改', '/apkconfig/' + marks + '/batchEditFile', 800, 600);
	} else {
		showMsg(market.content.title, market.content.tips, alert);
	}
}

function batchEditFileSubmit() {
	var rows = $('#tt').datagrid('getChecked');
	var marks = [];
	for (var i = 0; i < rows.length; i++) {
		marks.push(rows[i].mark);
	}
	$('#tf').form(
	'submit',
	{
		url : '/apkconfig/batchEditFileSubmit',
		onSubmit : function(param) {
			param.marks = marks
		},
		success : function(data) {
			$('#dlg1').dialog('close');
			var obj = eval('(' + data + ')');
			showMsg("提示", obj.return_msg, alert);
			$('#tt').datagrid('clearChecked');
			$('#tt').datagrid('reload');
			$('#tf').form('clear');
		},
		onLoadError : function() {
		}
	});
}

function batchEditLogin () {
	var rows = $('#tt').datagrid('getChecked');
	if (rows === undefined || rows.length == 0) {
		showMsg("温馨提示", "请选择要修改的记录！", alert);
		return false;
	}
	var marks = [];
	for (var i = 0; i < rows.length; i++) {
		marks.push(rows[i].mark);
	}
	
	if (rows) {
		showMyWindow('APK配置| 登录方式配置', '/apkconfig/' + marks + '/batchLoginList', 800, 400);
	} else {
		showMsg(market.content.title, market.content.tips, alert);
	}
}

function batchEditRetent () {
	var rows = $('#tt').datagrid('getChecked');
	if (rows === undefined || rows.length == 0) {
		showMsg("温馨提示", "请选择要修改的记录！", alert);
		return false;
	}
	var ids = [];
	for (var i = 0; i < rows.length; i++) {
		ids.push(rows[i].id);
	}
	
	if (rows) {
		showMyWindow('APK配置 | 批量留存限制', '/apkconfig/' + ids + '/batchEditRetent', 800, 400);
	} else {
		showMsg(market.content.title, market.content.tips, alert);
	}
}

function upgradeApk () {
	var rows = $('#tt').datagrid('getChecked');
	if (rows === undefined || rows.length == 0) {
		showMsg("温馨提示", "请选择要升级的记录！", alert);
		return false;
	}
	var ids = [];
	for (var i = 0; i < rows.length; i++) {
		ids.push(rows[i].id);
	}
	
	showMyWindow('APK配置 | 升级包', '/apkconfig/' + ids + '/toUpgradeApk', 800, 400);
}

function delUpgradeApk () {
	var rows = $('#tt').datagrid('getChecked');
	if (rows === undefined || rows.length == 0) {
		showMsg("温馨提示", "请选择要删除的记录！", alert);
		return false;
	}
	if (rows.length > 1) {
		showMsg("温馨提示", "请选择1条要删除的记录！", alert);
		return false;
	}
	var id = rows[0].id;
	showMyWindow('APK配置 | 升级包', '/apkconfig/' + id + '/toDelUpgradeApk', 800, 400);
}

